#ifndef CNC_BASE_WORK_OFFSET_IMPLEMENTATION_H
#define CNC_BASE_WORK_OFFSET_IMPLEMENTATION_H

#include "workofs.h"
#include "parameter.h"
#include <stdint.h>
#include <cassert>
#include <iostream>

namespace cnc {

	namespace base {

		template <unsigned int NUM_AXES>
		class WorkOffsetImpl : public WorkOffset
		{
			Parameter *offset_[NUM_AXES];
		public:
			WorkOffsetImpl()
			{
				for (int i = 0; i < NUM_AXES; i++)
					offset_[i] = 0;
			}
			bool assign(unsigned int axis, Parameter *param)
			{
				if (axis >= NUM_AXES)
					return false;
				offset_[axis] = param;
				return true;
			}
			virtual unsigned int getNumAxes()
			{
				return NUM_AXES;
			}
			virtual bool set(unsigned int axis, int32_t offset)
			{
				if (axis >= NUM_AXES) // axis out of range
					return false;
				if (offset_[axis] == 0) // axis not assigned
					return false;
				return offset_[axis]->set(offset);
			}
			virtual bool get(unsigned int axis, int32_t *offset)
			{
				if (axis >= NUM_AXES) // axis out of range
					return false;
				if (offset_[axis] == 0) // axis not assigned
					return false;
				return offset_[axis]->get(offset);
			}
		};

	} // namespace base

} // namespace cnc

#endif
